package cn.easybuy.service.impl;

import cn.easybuy.dao.ProductDao;
import cn.easybuy.dao.impl.ProductDaoImpl;
import cn.easybuy.entity.Product;
import cn.easybuy.service.ProductService;
import cn.easybuy.util.PageUtil;

public class ProductServiceImpl implements ProductService{
	private ProductDao dao = new ProductDaoImpl();
	@Override
	public PageUtil<Product> findProductsByCategoryId(int categoryId,int categoryLevel,int currPageNo,int pageSize) {
		
		//根据当前页码计算出SQL的起始索引
		int beginIndex = (currPageNo -1)*pageSize;
		
		return dao.findProductsByCategoryId(categoryId,categoryLevel,beginIndex,pageSize);
	}
	@Override
	public Product getProductById(int id) {
		// TODO Auto-generated method stub
		return dao.getProductById(id);
	}
	@Override
	public int subStock(int productId, int quantity) {
		// TODO Auto-generated method stub
		return dao.subStock(productId, quantity);
	}
	@Override
	public PageUtil<Product> findAllProducts(int currPageNo, int pageSize) {
		//根据当前页码计算出SQL的起始索引
		int beginIndex = (currPageNo -1)*pageSize;
		// TODO Auto-generated method stub
		return dao.findAllProducts(beginIndex, pageSize);
	}
	@Override
	public int add(Product product) {
		// TODO Auto-generated method stub
		return dao.add(product);
	}
	@Override
	public int update(Product product) {
		// TODO Auto-generated method stub
		return dao.update(product);
	}

}
